<template>
    <div class="formLibrary">
        <el-input
            v-model="text"
            controls-position="right"
            @input="handelInput"
            :type ="isaDisabled(iptAttritube.fieldAttribute, 'type')"
            :disabled="isaDisabled(iptAttritube.fieldAttribute, 'disabled')"
            :placeholder="iptAttritube.guideText"
            :maxlength="120"
        ></el-input>
    </div>
</template>

<script>
export default {
    props: {
        iptAttritube: {
            type: Object,
            default: () => {}
        },
    },
    data() {
        return {
            text: ''
        }
    },
    mounted() {
        if(!this.iptAttritube.fieldAttribute instanceof Object) {
            this.iptAttritube.fieldAttribute = JSON.parse(this.iptAttritube.fieldAttribute)
        }
    },
    methods: {
        handelInput() {
            let value = {
                value: this.text,
                state: true
            }
            this.$emit('handleChange', value)
        },
        isaDisabled(c, t) {
            let d = JSON.parse(c)
            if(t == 'type') {
                if(d.type != undefined) {
                    return d.type
                } else {
                    return 'text'
                }
            } else {
                if(this.iptAttritube.fieldType == 'relevanceProp') {
                    return true
                }
                if(d.disabled != undefined) {
                    return d.disabled
                } else {
                    return false
                }
            }
        },
        defaultData(d) {
            this.text = ''
            d.map(item => {
                if(item.customFieldId == this.iptAttritube.id) {
                    this.text = item.value
                }
            })
        },
        removeSure() {
            
        }
    }
}
</script>